import logging
from redis import StrictRedis


class Config(object):
    """项目的配置"""
    DEBUG = True

    # 给session加密
    SECRET_KEY = "L+rl/9x+BRxhgrY+5HCMuKccZuJ7kkHQ8tMgCv9INNzycpdYAMjfUFOQsmzmMvit"

    # 为数据库添加配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/info08"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # Redis 的配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # Session保存配置
    SESSION_TYPE = "redis"  # 指定session保存到redis中
    SESSION_USER_SIGNER = True  # 让cookie中的session_id 被加密签名处理
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)  # 指定session保存的位置
    SESSION_PERMANENT = False  # 设置需要过期为false， 永久不过期为true
    PERMANENT_SESSION_LIFETIME = 86400 * 2  # 过期时间

    # 默认日志等级
    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    """开发模式下的配置"""
    DEBUG = True


class ProductionConfig(Config):
    """生产模式下的配置"""
    DEBUG = False
    LOG_LEVEL = logging.WARNING


class TestingConfig(Config):
    """测试环境下的测试"""
    DEBUG = True
    TESTING = True


config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'testing': TestingConfig
}